package com.s7_compat.net;
import com.google.gson.Gson;
import com.s7.compat.network.exception.ERROR;
import com.s7.compat.network.listener.OnRequestListener;
import com.s7.compat.network.support.BaseObserver;
import com.s7.compat.type.typeimpl.ParameterizedTypeImpl;
import com.s7.compat.utils.StringUtils;

import okhttp3.ResponseBody;

public class NetObserver<T> extends BaseObserver<T> {

    public NetObserver() {
        super();
    }

    public NetObserver(OnRequestListener<T> listener) {
        super(listener);
    }

    @Override
    protected void onResponseBody(ResponseBody body) {
        try {
            String data = body.string();
            StringUtils.showLog("请求结果", data);

//            Result<T> result = new Gson().fromJson(data,
//                    new ParameterizedTypeImpl(Result.class, getType()));
//
//            onSuccess(result.getData());
        } catch (Exception e) {
            e.printStackTrace();
           onUnusual(ERROR.PARSE_ERROR, "解析错误");
        }
    }

    @Override
    public void onError(Throwable e) {
        super.onError(e);
    }
}
